<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 全排列：无重复数字,但是要考虑每个数字是否用过 */
            var permute = function (nums) {
                let result = []
                function backTracking(path, use) {
                    if (path.length == nums.length) {
                        return result.push([...path])
                    }
                    for (let i = 0; i < nums.length; i++) {
                        if (!use[i]) {
                            use[i] = true
                            path.push(nums[i])
                            backTracking(path, use)
                            path.pop()
                            use[i] = false
                        }
                    }
                }
                backTracking([], [])
                return result
            }
            console.log(permute([1, 2, 3]))
        </script>
    </body>
</html>
